package main

import (
	"develop_admin/controller"
	"develop_admin/proto/admin"
	"develop_admin/proto/product"
	"github.com/asim/go-micro/plugins/registry/consul/v3"
	"github.com/asim/go-micro/v3"
	"github.com/asim/go-micro/v3/registry"
	"log"
)

func main() {
	//register consul
	registry := consul.NewRegistry(func(options *registry.Options) {
		options.Addrs = []string{"43.138.147.44:8500"}
	})

	//micro server
	service := micro.NewService(
		micro.Name("develop_admin"),
		micro.Version("latest"),
		micro.RegisterTTL(10),
		micro.RegisterInterval(1),
		micro.Registry(registry),
	)

	//micro init
	service.Init()

	err := admin.RegisterAdminServiceHandler(service.Server(),new(controller.Admin))
	if err != nil {
		log.Fatal("failed to link :",err.Error())
	}

	product.RegisterProductHandler(service.Server(),new(controller.Product))

	service.Run()
}
